package com.agileboot.attendance.domain.acceptance;

import com.agileboot.attendance.domain.acceptance.model.AcceptanceModel;
import com.agileboot.attendance.domain.acceptance.model.AcceptanceModelFactory;
import com.agileboot.attendance.domain.acceptance.dto.AcceptanceQuery;
import com.agileboot.attendance.domain.acceptance.dto.AcceptanceRequest;
import com.agileboot.common.core.page.PageDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 验收单应用服务
 */
@Service
@RequiredArgsConstructor
public class AcceptanceApplicationService {
    
    private final AcceptanceModelFactory acceptanceModelFactory;

    /**
     * 创建验收单
     */
    @Transactional(rollbackFor = Exception.class)
    public void createAcceptance(AcceptanceRequest request) {
        AcceptanceModel model = acceptanceModelFactory.create();
        model.loadFromRequest(request);
        model.checkFields();
        model.insertAcceptance();
    }

    /**
     * 更新验收单
     */
    @Transactional(rollbackFor = Exception.class)
    public void updateAcceptance(Long acceptanceId, AcceptanceRequest request) {
        AcceptanceModel model = acceptanceModelFactory.loadById(acceptanceId);
        model.loadFromRequest(request);
        model.checkFields();
        model.updateAcceptance();
    }

    /**
     * 删除验收单
     */
    @Transactional(rollbackFor = Exception.class)
    public void deleteAcceptance(Long acceptanceId) {
        AcceptanceModel model = acceptanceModelFactory.loadById(acceptanceId);
        model.deleteAcceptance();
    }

    /**
     * 分页查询验收单
     */
    public PageDTO<AcceptanceModel> getAcceptancePage(AcceptanceQuery query) {
        return acceptanceModelFactory.selectPage(query);
    }

    /**
     * 获取验收单详情
     */
    public AcceptanceModel getAcceptanceInfo(Long acceptanceId) {
        return acceptanceModelFactory.loadById(acceptanceId);
    }
} 